Skip to content

feat: automate ERC20 automation #6665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

feat: automate ERC20 automation #6665

wants to merge 1 commit into from

Conversation

rv-bitgo
Copy link
Contributor

@rv-bitgo rv-bitgo commented Aug 8, 2025

In progress. Do not review.

WIN-6598

TICKET: WIN-6598

.filter((coin) => coin.features.includes(CoinFeature.SUPPORTS_ERC20))
.forEach((coin) => {
const coinNames = {
[coin.network.type]: coin.name,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would only populate for Mainnet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 543 to 544
Mainnet: `${coin.network.name}`,
Testnet: `t${coin.network.name}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be network name or coin name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, would fetch this from coin.name now.

Comment on lines 28 to 35
.forEach((coin) => {
//TODO: Decide if it should stay here, maybe move to network or coin itself.
const coinNames = {
Mainnet: `${coin.network.name}`,
Testnet: `t${coin.network.name}`,
};

EthLikeErc20Token.createTokenConstructors(coinNames).forEach(({ name, coinConstructor }) => {
sdk.register(name, coinConstructor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll end up calling createTokenConstructors multiple time. One for each token.
I don't think that's the expected behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A valid catch. 👍
Since it was implemented on tokens instead of parent coin, the loop would call all tokens and register all tokens for each individual tokens.
Since we've moved the approach to parent coin instead of tokens, this would be fine now.

@@ -20,6 +21,20 @@ export const register = (coinFamily: string, sdk: BitGoBase): void => {
.forEach((coin) => {
sdk.register(coin.name, EvmCoin.createInstance);
});
//TODO: add token registration after EVM Token Optimisation is implemented
}
if (coins.get(coinFamily).features.includes(CoinFeature.IS_ERC20_TOKEN)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to add the feature to coin, then let's rework the feature name.
Current feature name suggests the coin is token as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea was to use this flag with tokens instead of parent coin, hence the name IS_ERC20_TOKEN. I've now updated it to SUPPORTS_ERC20.

export class EthLikeERC20Token extends ContractAddressDefinedToken {
public readonly coinNames: { Mainnet: string; Testnet: string };

constructor(options: Erc20ConstructorOptions & { coinNames: { Mainnet: string; Testnet: string } }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why take this as constructor params. Evaluate if we can derive this from the Network

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from constructors and static properties. It'd be fetched from coin name now. As discussed, we would not make this part of the network property as it's the same as coin.name in all of our use cases.

Comment on lines 26 to 34
if (coinFeatures.includes(CoinFeature.SUPPORTS_ERC20)) {
coins
.filter((coin) => coin.family === coinFamily && !coin.isToken)
.forEach((coin) => {
const coinNames = {
Mainnet: `${coin.name}`,
Testnet: `${coin.name}`,
};

EthLikeErc20Token.createTokenConstructors(coinNames).forEach(({ name, coinConstructor }) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not be moved inside the previous loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Lets put them in one loop.

@rv-bitgo rv-bitgo marked this pull request as ready for review August 14, 2025 10:58
@rv-bitgo rv-bitgo requested review from a team as code owners August 14, 2025 10:58
Copy link
Contributor

@yash-bitgo yash-bitgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are failing

@rv-bitgo
Copy link
Contributor Author

tests are failing

Fixed the browser test. 22.x is failing for all PRs(most likely due to mismatch versions).

WIN-6598

TICKET: WIN-6598

chore: add EthLikeErc20 to index.ts for export

TICKET: WIN-6598

chore: remove tokenConfig changes and rename feature flag

TICKET: WIN-6598

chore: create CoinNames on the go instead of generic

TICKET: WIN-6598

chore: fetch coinNames from coin name at runtime

TICKET: WIN-6598

feat: one loop for coin and token registration

TICKET: WIN-6598

chore: add the browser test for the new token class

TICKET: WIN-6598
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants